package com.hevs.samplewebapp.client.bean;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
 * Enum Class of category
 * <p>The goal is to map indexes to name for the time categories</p>
 * 
 * @author Matthias Hurni
 * @date 26.03.2012
 */
public enum Category
{
	/**
	 * Default selection
	 */
	NONE(0,"None"),

	/**
	 * After breakfast
	 */
	BREAKFAST(1,"After breakfast"),

	/**
	 * After lunch
	 */
	LUNCH(2,"After lunch"),

	/**
	 * After dinner
	 */
	DINNER(3,"After dinner");

	/**
	 * numerical representation of the moment of the day
	 */
	private int level;

	/**
	 * name of the moment of the day
	 */
	private final String name;

	/**
	 * Map of all the categories
	 */
	private static final Map<Integer,Category> lookup=new HashMap<Integer,Category>();

	// ----------------------------------------------------------------------------
	// Constructor
	// ----------------------------------------------------------------------------
	
	/**
	 * Constructor of the category to map a name to a number
	 * @param level
	 * 	numerical representation of the moment of the day
	 * @param name
	 * 	name of the moment of the day
	 */
	private Category(int level,String name)
	{
		this.level=level;
		this.name=name;
	}

	// ----------------------------------------------------------------------------
	// Methods
	// ----------------------------------------------------------------------------
	/**
	 * method to create category with level and name
	 */
	static
	{
		for(Category c:EnumSet.allOf(Category.class))
			lookup.put(c.getLevel(),c);
	}


	/**
	 * Returns the integer value of this level (greater value, later in the day)
	 */
	public int getLevel()
	{
		return level;
	}

	/**
	 * Returns the name of this level
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Returns the size of the Enum
	 */
	public static int getSize()
	{
		return Category.values().length;
	}

	/**
	 * Returns the Category Enum
	 */
	public static Category get(int level)
	{
		return lookup.get(level);
	}

	/**
	 * toString method of the category
	 */
	public String toString()
	{
		return name;
	}
}
